package com.pxst.demo.controller;

import java.lang.reflect.Method;
import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codingapi.txlcn.tc.annotation.DTXPropagation;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.google.common.collect.Lists;
import com.pxst.demo.mapper.TestMapper;
import com.pxst.resp.ApiResp;
import com.pxst.sys.mapper.Test2Mapper;
import com.pxst.utils.PlugsUtils;

/** 
* @author yangxy
* @version 创建时间：2023年7月28日 上午11:46:16 
*/
@Service
@Transactional
public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> implements TestService {

	@Override
	@Transactional//本地事务
	@LcnTransaction(propagation = DTXPropagation.SUPPORTS)//分布式事务参与方
	public ApiResp<String> test(String name) {
		// TODO Auto-generated method stub
		TestEntity t = new TestEntity();
		t.setName(name);
		save(t);
		return ApiResp.sucess();
	}

	@Autowired
	private PlugsUtils plugsUtils;

	@Autowired
	private Test2Mapper test2Mapper;
	
	@Override
	public void test()  {
		// TODO Auto-generated method stub
		Test2 t = new Test2();
		t.setName("test");
		test2Mapper.insert(t);
		Object plugsExec = plugsUtils.plugsExec("com.pxst.TaskDemo", "test", null);
//		try {
//			Object obj = applicationContext.getBean("com.pxst.TaskDemo");
//			Method method = obj.getClass().getMethod("test");
//			Object invoke = method.invoke(obj);
//			System.out.println("====>" + JSON.toJSONString(invoke));
//		} catch (Exception e) {
//			// TODO: handle exception
//			throw new RuntimeException();
//		}
	}

}
